package com.mayuanfei.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * TODO 类描述
 *
 * @author 老马
 * @date 2023-03-24 14:16
 */
@Controller
public class PathController {
    /**
     * 通过路径获得参数值
     * @param userid 用户id
     * @param username 用户姓名
     * @return first页面
     */
    @RequestMapping("/path/variable/{userid}/{username}")
    public String pathVariable(@PathVariable(value = "userid") Integer userid,
                               @PathVariable(value = "username", required = false) String username) {
        System.out.println("userid:" + userid);
        System.out.println("username:" + username);
        return "first";
    }

    @RequestMapping(value = "testRest/{id}", method = RequestMethod.GET)
    @ResponseBody
    public String testRestGet(@PathVariable String id) {
        return "test rest GET :" + id;
    }

    @RequestMapping(value = "testRest/{id}", method = RequestMethod.POST)
    @ResponseBody
    public String testRestPost(@PathVariable String id) {
        return "test rest POST :" + id;
    }

    @RequestMapping(value = "testRest/{id}", method = RequestMethod.PUT)
    @ResponseBody
    public String testRestPut(@PathVariable String id) {
        return "test rest PUT :" + id;
    }

    @RequestMapping(value = "testRest/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public String testRestDelete(@PathVariable String id) {
        return "test rest DELETE :" + id;
    }


}